﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_PGFBSQAddControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox 项目名称, 征收范围, txt需征收房屋面积, txt被征收居民户数, txt工企单位数, txt申请单位, txt经办人, txt经办人联系电话, txtPNID, txtID;
        MPCalendar txt申请时间;
        DropDownList txt资质;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
            string strpnid = base.Page.Request["PNID"];
            if (!base.Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(strpnid)) {
                    //txtPNID.Text = strpnid;
                    //EluZSProvider.Prono prono = GetProno(strpnid);
                    //string strpid = prono.PID;
                    //if (!string.IsNullOrEmpty(strpnid))
                    //{
                        EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(strpnid);
                        项目名称.Text = project.项目名称;
                        征收范围.Text = project.征收范围;
                        txt需征收房屋面积.Text = project.被征收房屋面积合计;
                        txt被征收居民户数.Text = project.被征收居民户口户数;
                        txt工企单位数.Text = project.被征收工企单位;
                        txt申请单位.Text = project.申请单位;
                        txt申请时间.Text = DateTime.Now.ToString();
                    //}
                }
                if (string.IsNullOrEmpty(base.Page.Request["ID"])) {
                    txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "");
                }
            }
        }

        public Prono GetProno(string pnid)
        {
            Prono project = new Prono();
            string sql = @"select * from zs_prono where pid ='" + pnid + "'";
            DataTable dt = null;
            dt = _EluZSDataProvider.GetTable(sql);
            return project = DataHelper.DataTableToTOne<Prono>(dt);
        }

      

        protected void InitControl()
        {
            项目名称 = (TextBox)FindControl("项目名称");
            征收范围 = (TextBox)FindControl("征收范围");
            txt需征收房屋面积 = (TextBox)FindControl("txt需征收房屋面积");
            txt被征收居民户数 = (TextBox)FindControl("txt被征收居民户数");
            txt工企单位数 = (TextBox)FindControl("txt工企单位数");

            txt申请单位 = (TextBox)FindControl("txt申请单位");
            txt经办人 = (TextBox)FindControl("txt经办人");
            txt经办人联系电话 = (TextBox)FindControl("txt经办人联系电话");
            txt申请时间 = (MPCalendar)FindControl("txt申请时间");
            txtPNID = (TextBox)FindControl("txtPNID");

            txtID = (TextBox)FindControl("txtID");
            txt资质 = (DropDownList)FindControl("txt资质");
        }



        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            string sql = "Select name From zs_user Where Id = '"+userid+"'";
            string name = _EluZSDataProvider.GetString(sql);
            string sql1 = @"select * from zs_prono where pid ='" + base.Page.Request["pnid"] + "'";
            string strpnid = _EluZSDataProvider.GetString(sql1);
            EluZSProvider.PGFBSQ pgfbsq = new PGFBSQ();
            pgfbsq.ID = txtID.Text;
            pgfbsq.PNID = Page.Request["Pnid"];
            pgfbsq.需征收房屋面积 = txt需征收房屋面积.Text.Trim();
            pgfbsq.被征收居民户数 = txt被征收居民户数.Text.Trim();
            pgfbsq.工企单位数 = txt工企单位数.Text.Trim();
            pgfbsq.申请单位 = txt申请单位.Text.Trim();
            pgfbsq.经办人 = txt经办人.Text.Trim();
            pgfbsq.经办人联系电话 = txt经办人联系电话.Text.Trim();
            pgfbsq.资质 = txt资质.SelectedValue;
            pgfbsq.申请时间 = (string.IsNullOrEmpty(txt申请时间.Text) ? null : (DateTime?)Convert.ToDateTime(txt申请时间.Text));
            pgfbsq.操作人员 = name;
            pgfbsq.记录当前时间 = System.DateTime.Now;
            bool save = _EluZSDataProvider.SavePgfbsq(base.Page.Request["ID"], pgfbsq);
            if (save) { base.Page.Response.Write("<script>alert('保存成功！');location.href=('zs_pgfbsqadd.aspx?pnid="+Page.Request["Pnid"]+"');</script>"); }
        }
    }
}


